﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using HCRS.DBACL;
using System.Text;
using Common;
using HCRS.Implementation;
using System.Collections;
namespace EZCRS.HCMS.DataAcl
{
    /// <summary>
    /// AjaxClass 的摘要说明
    /// </summary>
    public class AjaxClass
    {
        DataAccessLayer _DataAccessLayer = new DataAccessLayer();
        CommonWeb _CommonClass = new CommonWeb();
        SearchHotelClass search = new SearchHotelClass();

        public AjaxClass()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        #region 读取文件
        public static string ReadFile(string path)
        {
            try
            {
                StreamReader sr = File.OpenText(path);
                string Content = sr.ReadToEnd();
                sr.Close();
                sr = null;
                return Content;
            }
            catch (Exception)
            {
                return "文件不存在！";
            }
        }
        #endregion

        #region 验证码产生
        /// <summary>
        /// 验证码产生
        /// </summary>
        /// <returns></returns>
        public static string GenerateCheckCode()
        {
            string checkCode = String.Empty;
            System.Random random = new Random(System.DateTime.Now.Millisecond);
            checkCode = "0000" + random.Next(9999);
            checkCode = checkCode.Substring(checkCode.Length - 4, 4);
            HttpContext.Current.Session["Field_validateCode"] = checkCode;
            HttpContext.Current.Session["Field_IP"] = HttpContext.Current.Request.UserHostAddress;
            HttpContext.Current.Session["Field_MName"] = HttpContext.Current.Request.UserAgent;
            return checkCode;
        }
        /// <summary>
        /// 验证码图片生成
        /// </summary>
        /// <param name="checkCode"></param>
        public static void CreateCheckCodeImage(string checkCode)
        {
            if (checkCode == null || checkCode.Trim() == String.Empty)
                return;
            System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
            Graphics g = Graphics.FromImage(image);
            try
            {
                //生成随机生成器
                Random random = new Random();

                //清空图片背景色
                g.Clear(Color.White);

                //画图片的背景噪音线
                for (int i = 0; i < 25; i++)
                {
                    int x1 = random.Next(image.Width);
                    int x2 = random.Next(image.Width);
                    int y1 = random.Next(image.Height);
                    int y2 = random.Next(image.Height);

                    g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
                }

                Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Green, Color.Green, 1.2f, true);
                g.DrawString(checkCode, font, brush, 2, 2);

                //画图片的前景噪音点
                for (int i = 0; i < 100; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);

                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }

                //画图片的边框线
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ContentType = "image/Gif";
                HttpContext.Current.Response.BinaryWrite(ms.ToArray());
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }
        #endregion

        #region 酒店信息图片
        public string getHotelID(int property_id)
        {
            string[] hotel = _DataAccessLayer.RunSqlStrings("select Hotel_ID from [hotel] where pid=" + property_id + " ");
            if (hotel != null && hotel.Length > 0)
            {
                return hotel[0];
            }
            else
            {
                return "0";
            }
        }
        public   void PrintHotel(int property_id,int lancode)
        {
            string title = "";
            string bgtitle = "";
            Point point = new Point();
            string font = "Verdana";
            int lean = -45;
            if (lancode != 0)
            {
                title = "Hotel address in Chinese for taxi drivers";
                bgtitle = FGBCommon.GetConfiguration("imgsignen");
                point = new Point(100, 150);
                font = "Verdana";
                lean = -30;
            }
            else
            {
                point = new Point(200, 200);
                font = "Arial";
                lean = -45;
                bgtitle = FGBCommon.GetConfiguration("imgsignzh");
                title = "出示给出租车司机的酒店地址";
            }

            string[] hotel = _DataAccessLayer.RunSqlStrings("select Title,Title_e,Address1,Phone,Fax from [hotel] where Hotel_ID=" + property_id + " ");
            
                string tip = "     Hotel address in Chinese for taxi drivers     ";
                System.Drawing.Bitmap image = new System.Drawing.Bitmap(446, 267);//("hotelinfo.jpg");//(446, 267);
                Graphics g = Graphics.FromImage(image);
                try
                {
                    g.Clear(Color.White);

                    Font afont = new System.Drawing.Font("Arial", 14,System.Drawing.FontStyle.Bold);
                    Font cfont = new System.Drawing.Font("黑体", 16,System.Drawing.FontStyle.Bold);

                    Color cbule=Color.FromArgb(Convert.ToInt16("0x00",16),Convert.ToInt16("0x33",16),Convert.ToInt16("0x99",16));
                    Color cgreen=Color.FromArgb(Convert.ToInt16("0x99",16),Convert.ToInt16("0xCC",16),Convert.ToInt16("0x00",16));
                    Color cgray = Color.FromArgb(Convert.ToInt16("0x00", 16), Convert.ToInt16("0x33", 16), Convert.ToInt16("0x99", 16));
                
                    DrawRoundRectangle(g, new Pen(cgreen, 3), new Rectangle(1, 1, image.Width - 4, image.Height - 4), 10);

                    PointF rotatePoint = new PointF(200, 200);
                    SizeF size = g.MeasureString(bgtitle,  new System.Drawing.Font(font,48));
                    Brush brush = new SolidBrush(Color.FromArgb(Convert.ToInt16("0xEC", 16), Convert.ToInt16("0xF6", 16), Convert.ToInt16("0xD0", 16)));
                    Matrix myMatrix = new Matrix();
                    myMatrix.RotateAt(lean, rotatePoint, MatrixOrder.Append);
                    g.Transform = myMatrix;
                    g.DrawString(bgtitle, new System.Drawing.Font(font, 48), brush, point);// (rotatePoint.X - size.Width) / 2,( rotatePoint.Y - size.Height) / 2);
                    myMatrix = new Matrix();
                    g.Transform = myMatrix;

                    brush = new SolidBrush(Color.FromArgb(Convert.ToInt16("0x00", 16), Convert.ToInt16("0x33", 16), Convert.ToInt16("0x99", 16)));
                  
                    g.DrawString(title, afont, brush, 20, 15);
                   
                    g.DrawLine(new Pen(cgreen), 20, 40,420, 40);

                    brush = new SolidBrush(Color.FromArgb(Convert.ToInt16("0x66", 16), Convert.ToInt16("0x66", 16), Convert.ToInt16("0x66", 16)));
                   
                    if (hotel != null && hotel.Length > 0)
                    {
                        g.DrawString(hotel[0], cfont, brush, 20, 55);
                        g.DrawString(hotel[1], afont, brush, 20, 95);
                        g.DrawString("地址:" + hotel[2], cfont, brush, 20, 135);
                        g.DrawString("电话:" + hotel[3], cfont, brush, 20, 175);
                        g.DrawString("传真:" + hotel[4], cfont, brush, 20, 215);
                    }
                    else
                    {
                        g.DrawString("酒店不存在", cfont, brush, 20, 60);
                    }
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.ContentType = "image/jpeg";
                    HttpContext.Current.Response.BinaryWrite(ms.ToArray());
                }
                finally
                {
                    g.Dispose();
                    image.Dispose();
                }
        
        }

        private static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rect, int cornerRadius)
        {
            using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
            {
                g.DrawPath(pen, path);
            }

        }
        private static void FillRoundRectangle(Graphics g, Brush brush, Rectangle rect, int cornerRadius)
        {
            using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
            {
                g.FillPath(brush, path);
            }
        }
        private static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
        {
            GraphicsPath roundedRect = new GraphicsPath();
            roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
            roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
            roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
            roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
            roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
            roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            return roundedRect;
        } 

        #endregion

        #region 酒店背景信息图片
    
        public void PrintHotelImage(int property_id, int lancode)
        {
            string title = "";
            string bgtitle = "";
            Point point = new Point();
            string font = "Verdana";
            string originalImagePath = "";
            if (lancode != 0)
            {
                originalImagePath =HttpContext.Current.Request.PhysicalApplicationPath+ "\\images\\hotelinfoimgen.gif";
            }
            else
            {
                originalImagePath = HttpContext.Current.Request.PhysicalApplicationPath + "\\images\\hotelinfoimgcn.gif";
            }
            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);
            string[] hotel = _DataAccessLayer.RunSqlStrings("select Title,Title_e,Address1,Phone,Fax from [hotel] where Hotel_ID=" + property_id + " ");
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(originalImage.Width, originalImage.Height);
            Graphics g = System.Drawing.Graphics.FromImage(image);        
            g.DrawImage(originalImage,new Point(0,0));  
            try
            {
                Font afont = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
                Font cfont = new System.Drawing.Font("宋体", 16, System.Drawing.FontStyle.Bold);
                Font mfont = new System.Drawing.Font("宋体", 13, System.Drawing.FontStyle.Bold);
                Color cgray = Color.FromArgb(Convert.ToInt16("0x43", 16), Convert.ToInt16("0x43", 16), Convert.ToInt16("0x49", 16));
                Brush brush = new SolidBrush(cgray);
                float left = 15;
                float r_left = left + 45;
                float rowInit = 50;
                float rowheight = 30;
                float wordheight = 20;
                if (hotel != null && hotel.Length > 0)
                {
                    g.DrawString(hotel[0], cfont, brush, 15, rowInit);//中文名称
                    g.DrawString(hotel[1], afont, brush, 15, rowInit+rowheight);//英文名称
                    if (hotel[2].Length > 15)
                    {                      
                        string[]str= GetTwoRows(hotel[2], 15);
                        g.DrawString("地址:" + str[0], mfont, brush, 15, rowInit + rowheight*2);
                        g.DrawString(str[1], mfont, brush, 60, rowInit + rowheight*2 + wordheight);
                        g.DrawString("电话:" + hotel[3], mfont, brush, 15, 160);
                    }
                    else
                    {
                        g.DrawString("地址:" + hotel[2], mfont, brush, 15, rowInit + rowheight*2);
                        g.DrawString("电话:" + hotel[3], mfont, brush, 15, rowInit + rowheight*3);
                    }
                   // g.DrawString("传真:" + hotel[4], mfont, brush, 15, 165);
                }
                else
                {
                    g.DrawString("酒店不存在", cfont, brush, 20, 60);
                }
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ContentType = "image/jpeg";
                HttpContext.Current.Response.BinaryWrite(ms.ToArray());
                
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }

        }
        public static string[] GetTwoRows(string str,int split)
        {
            if (str.Length <= split)
            {
                return new string[] { str,""};
            }
            string[] temp = new string[2];
            temp[0] = str.Substring(0, split);
            temp[1] = str.Substring(split, str.Length - split);
            char first=temp[1].ToCharArray(0,1)[0];

            if (!((48 <= first && first <= 57) || (65 <= first && first <= 90) || (97 <= first && first <= 122)))//首字符不是英文或数字
            {
                return temp;
            }
           

            char[] test = temp[0].ToCharArray();
            split = 0;
            for (int j = test.Length - 1; j > 0; j--)
            {
                first = test[j];
                if (first == 32) break;
                if ((48 <= first && first <= 57) || (65 <= first && first <= 90) || (97 <= first && first <= 122))
                {
                    temp[1] = test[j].ToString() + temp[1];
                    split++;
                }
                else
                {
                    break;
                }
            }
            temp[0]=temp[0].Substring(0, temp[0].Length - split);
            return temp;
        }
    
        #endregion

        #region 发送确认码
        [AjaxPro.AjaxMethod]
        public string SendRadom(string Mobile, string imgCode)
        {
            if (HttpContext.Current.Session["Field_validateCode"] != null)
            {
                if (HttpContext.Current.Session["Field_validateCode"].ToString().ToUpper() == imgCode.ToUpper())
                {
                    string MobileNo = Mobile;
                    string validateCode = GetvalidateMobile();
                    string IPAddress = HttpContext.Current.Session["Field_IP"].ToString();
                    string SessionID = HttpContext.Current.Session.SessionID;
                    string MName = HttpContext.Current.Session["Field_MName"].ToString();
                    new DataAccessLayer().RunSql("exec  Insert_HFG_MobileValidate '" + MobileNo + "','" + validateCode + "','" + IPAddress + "','" + SessionID + "','' ;");
                    return "1|手机短信发送中，请注意查收手机短信！";
                }
                else
                {
                    return "0|图片附加码错误,请重新输入!";
                }
            }
            else
            {
                return "0|系统错误！请刷新页面!";
            }
        }
        private string GetvalidateMobile()
        {
            string checkCode = String.Empty;
            System.Random random = new Random(System.DateTime.Now.Millisecond);
            checkCode = "000000" + random.Next(999999);
            checkCode = checkCode.Substring(checkCode.Length - 6, 6);
            return checkCode;
        }
        #endregion

        #region 确认码校验
        [AjaxPro.AjaxMethod]
        public string ValidateMobile(string Mobile, string imgCode, string validateCode)
        {
            if (HttpContext.Current.Session["Field_validateCode"] != null)
            {
                if (HttpContext.Current.Session["Field_validateCode"].ToString().ToUpper() == imgCode.ToUpper())
                {
                    string MobileNo = Mobile;
                    string IPAddress = HttpContext.Current.Session["Field_IP"].ToString();
                    string SessionID = HttpContext.Current.Session.SessionID;

                    _DataAccessLayer.ClearParameter();
                    _DataAccessLayer.addNewParameter("@MobileNo", MobileNo, 11);
                    _DataAccessLayer.addNewParameter("@validateCode", validateCode, 20);
                    _DataAccessLayer.addNewParameter("@IPAddress", IPAddress, 24);
                    _DataAccessLayer.addNewParameter("@SessionID", SessionID, 200);
                    DataTable dt = _DataAccessLayer.RunStoreDataTable("Get_FIT_MobileValidate");

                    return dt.Rows[0][0].ToString().Trim();
                }
                else
                {
                    return "0";
                }
            }
            else
            {
                return "0";
            }
        }
        #endregion        

        #region 用户校验
        [AjaxPro.AjaxMethod]
        public string ValidateUser(int gid,string username, string password,string vtype,string days)
        {
            string msg = "";
            try
            {
                FGBUserClass user = new FGBUserClass();
                bool login = FGBRoleSystems.ValidateUser(gid, username, password, (ValidateType)Enum.Parse(typeof(ValidateType), vtype), (CookieDays)Enum.Parse(typeof(CookieDays), days),out user,out msg);

                if (user.usrstatus)
                {
                    return "2|帐户已冻结，请网站管理员！";
                }
                if (login)
                {
                    return "1|已成功登录！";
                }
                else
                {
                    return "0|用户不存在或用户名密码错误！";
                }
            }
            catch (Exception e)
            {
                HCRS.Implementation.Error.Log(e,"","登录",username,"FGBWeb");
                return "0|用户不存在或用户名密码错误！";
            }
        }
        #endregion

        #region 酒店评价
        [AjaxPro.AjaxMethod]
        public string SendComment(int property_id, string Comment, int Score)
        {
            string IPAddress = HttpContext.Current.Request.UserHostAddress;//HttpContext.Current.Session["Field_IP"].ToString();
            string SessionID = HttpContext.Current.Session.SessionID;
            string MName = "";
            if (property_id == 0)
            {
                return "0|酒店不存在!";
            }
            try
            {
                if (!_DataAccessLayer.RunSqlExists("select * from HFG_HotelComment where property_id=" + property_id + " and Convert(varchar(10),InTime,120)=Convert(varchar(10),getdate(),120) and SessionID=" + property_id + ""))
                {


                    Comment = _CommonClass.VerifySQL(Comment);
                    Comment = Comment.Replace("--", "——");
                    Comment = Comment.Replace("<", " &lt;").Replace(">", "&gt;").Replace("script","s c r i p t") ;
                    Comment = Comment.Replace("write", "w r i t e");
                    Comment = Comment.Replace("document","d o c u m e n t").Replace("window","w i n d o w");
                    string[] ziduan = "property_id, Score, Comment, IPAddress, SessionID, MName".Split(',');
                    string[] strvalue = new string[6] { property_id.ToString(), Score.ToString(), Comment, IPAddress, SessionID, MName };
                    _DataAccessLayer.InsertDataStr("[HFG_HotelComment]", ziduan, strvalue);
                    if (_DataAccessLayer.ErrorMsg.Length > 2)
                    {

                        return "0|保存错误,请重新提交!";
                    }
                    else
                    {
                        return "1|保存成功!";
                    }
                }
                else
                {
                    return "0|已经评论过此酒店!";
                }
            }
            catch (Exception)
            {
                return "0|保存失败!";
            }
        }
        #endregion

        #region 酒店评论合计
        [AjaxPro.AjaxMethod]
        public string GetComment(int property_id)
        {
            _DataAccessLayer.ClearParameter();
            _DataAccessLayer.addNewParameter("@property_id", property_id);
            DataTable dt = _DataAccessLayer.RunStoreDataTable("Get_FIT_HotelComment_Result");
            return dt.Rows[0][0].ToString().Trim();
        }
        #endregion

        #region 酒店评论详情
        [AjaxPro.AjaxMethod]
        public string GetCommentList(int property_id)
        {
            _DataAccessLayer.ClearParameter();
            _DataAccessLayer.addNewParameter("@property_id", property_id);
            DataTable dt = _DataAccessLayer.RunStoreDataTable("Get_FIT_HotelComment_List");
            if (dt == null || dt.Rows.Count < 1)
            {
                return "暂无评论！请点击右上角的星号发表您的评论建议！";
            }
            StringBuilder str = new StringBuilder("<table  class=table_Gird   cellspacing=\"0\" cellpadding=\"3\">");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //if (i % 2 == 0)
                //{
                //    str.Append("<tr class=td_Gird>");
                //}
                //else
                //{
                //    str.Append("<tr class=td_AltGird>");
                //}
                str.Append("<tr class=td_Gird><td>评分：" + dt.Rows[i]["Score"].ToString() + "</td><td>时间：" + dt.Rows[i]["InTime"].ToString() + "</td><td>IP：" + dt.Rows[i]["IP"].ToString() + "</td></tr>");
                str.Append("<tr class=td_AltGird><td colspan=3 align=\"left\">" + dt.Rows[i]["Comment"].ToString().Replace("\r", "<br/>").Replace("\n", "<br/>") + "</td></tr>");
            }
            str.Append("</table>");
            return str.ToString();
        }
        #endregion  

        #region 获取酒店名称
        [AjaxPro.AjaxMethod]
        public string GetHotelName(int property_id)
        {
            string[] hotel = _DataAccessLayer.RunSqlStrings("select title from [hotel] where Hotel_ID=" + property_id + " ");
            if (hotel != null && hotel.Length > 0)
            {
                return hotel[0];
            }
            else
            {
                return "酒店名称";
            }

        }
        #endregion

        #region 获取订单列表
        [AjaxPro.AjaxMethod]
        public string GetOrders()
        {
            StringBuilder str=new StringBuilder();
            str.Append("<table width=\"100%\" style=\"table-layout: auto; border-collapse: collapse\"><tr><td>酒店名称</td><td>预订确认号</td><td>入住日期/离店日期</td><td></td></tr>");
            return str.ToString();
        }        
#endregion


        #region 用户注册

        #region 检测用户名是否存在
        /// <summary>
        /// 检测用户名是否存在
        /// </summary>
        /// <param name="user">用户名</param>
        /// <returns>0 不存在 1 存在</returns>
        [AjaxPro.AjaxMethod]
        public int IsExistUserName(int gid,string user)
        {
            if(FGBUserSystems.IsExistUserName(gid,user))
            {
                return 1;
            }
            return 0;
        }
        #endregion

        #region 检测Email是否已被使用
        /// <summary>
        /// 检测用户名是否存在
        /// </summary>
        /// <param name="mail">邮件地址</param>
        /// <returns>0 不存在 1 存在</returns>
        [AjaxPro.AjaxMethod]
        public int IsExistEmail( int gid,string mail)
        {
            if (FGBUserSystems.IsExistEmail(gid,mail )) 
            {
                return 1;
            }
            return 0;
        }


        #endregion

        #region 检测Email是否已被使用
        /// <summary>
        /// 检测用户名是否存在
        /// </summary>
        /// <param name="mail">邮件地址</param>
        /// <returns>0 不存在 1 存在</returns>
        [AjaxPro.AjaxMethod]
        public int IsExistMobile(int gid,string Mobile )
        {
            if (FGBUserSystems.IsExistMobile( gid,Mobile))
            {
                return 1;
            }
            return 0;
        }


        #endregion
        [AjaxPro.AjaxMethod]
        public static string Register(int gid,int hid, string username, string usrpassword, string usremail, string usrmobile, bool ademail, bool admobile)
        {
           string  msg = "";
           FGBGroup fgb = new FGBGroup();
           fgb.languagetype = 0;
           fgb.gid = gid;
           fgb.hid = hid;
           fgb = FGBRoleSystems.GetFGBEngine(fgb);
           bool flag = FGBRoleSystems.hfg_userInsert(fgb.emailfrom, fgb.emailalias, gid, username, usrpassword, usremail, usrmobile, ademail, admobile, true, out msg);
            if (flag)
            {
                return "1|" + msg;
            }
            else
            {
                return "0|" + msg;
            }
           
        }
  

        #endregion


        #region 获取安全问题提示
        /// <summary>
        /// 获取安全问题提示
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string GetQuestion(string username)
        {
            string PasswordQuestion = "";
            if(username==null)
            {
                return "0|The Username you provided doesn't match our records, please check and try again";
            }
            else
            {
                return  "1|"+username+"|"+PasswordQuestion;
            }
        }

          /// <summary>
        /// 获取安全问题提示
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string GetEmailQuestion(string email)
        {
            string username = "";//Membership.GetUserNameByEmail(email);
            string PasswordQuestion="";
            if (username == null)
            {
                return "0|用户不存在，请检查Email是否错误！";
            }
            if (PasswordQuestion == null)
            {
                return "0|用户不存在，请检查Email是否错误！";
            }
            else
            {
                return  "1|"+username+"|"+PasswordQuestion;
            }
        }

        #endregion

        #region 系统重设密码
        /// <summary>
        /// 系统重设密码
        /// </summary>
        /// <param name="username"></param>
        /// <param name="Answer"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string SendPassWord(string username, string Answer)
        {
            return "1|over";
            //string msg = "";
            //try
            //{
            //    FGBUserClass user=new FGBUserClass();;
            //    string Password = user.ResetPassword(Answer);
            //    string newpassword = RoleSystems.CreatePassWord(6);
            //    user.ChangePassword(Password, newpassword);
            //    string url = HttpContext.Current.Request.UrlReferrer.ToString().Split('?')[0];
            //    int l = url.LastIndexOf("/");
            //    url = url.Substring(0, l);
            //    string text = "";
            //    string temppath = url.Replace("http://", "");
            //    l = temppath.IndexOf("/");
            //    temppath = temppath.Substring(l, temppath.Length - l);

            //    string path = HttpContext.Current.Server.MapPath(temppath + "/mail") + "\\Email_ForgetPassword.txt";  
            //    string content = ReadFile(path).Replace("[$url$]", url).Replace("[$username$]", username).Replace("[$password$]", newpassword);
            //    if (RoleSystems.sendFGBemail(user.Email, "Recovery password E-mail", content , out msg))
            //    {
            //        return "1|" + user.Email;
            //    }
            //    else
            //    {
            //        throw new Exception("Email Send Fail!");
            //    }
            //}
            //catch(Exception e)
            //{
            //    return "0|"+e.ToString();
            //}
        }
        #endregion

        #region 修改邮箱
        /// <summary>
        /// 修改邮箱
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="oemail"></param>
        /// <param name="nemail"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string ChangeEmail(string username, string password, string oemail, string nemail)
        {
            return "";
            //string msg="";
            //if (username != RoleSystems.UserName)
            //{
            //    return "0|Username is wrong!";
            //}
            //if (!Membership.ValidateUser(username, password))
            //{
            //    return "0|Password is wrong";
            //}
            //if (RoleSystems.UpdateEmail(username, oemail, nemail, out msg))
            //{
            //    return "1|Change Email Success !";
            //}
            //else
            //{
            //    return "0|Change fail!";
            //}
        }
        #endregion

        #region 更改密码
        /// <summary>
        /// 更改密码
        /// </summary>
        /// <param name="opassword"></param>
        /// <param name="npassword1"></param>
        /// <param name="npassword2"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string ChangePassword(string opassword, string npassword1, string npassword2)
        {
            //if (npassword1.Length < 4)
            //{
            //    return "0|New password was too short!";
            //}
            //if (npassword1 != npassword2)
            //{
            //    return "0|The new password does not match!";
            //}
            //if (RoleSystems.ChangePassword(RoleSystems.UserName,opassword, npassword1))
            //{
            //    return "1|You have successfully changed your password.";
            //}
            //else
            //{
            //    return "0|Password reset failed. Please check your old password.";
            //}
            return "";
        }
        #endregion

        [AjaxPro.AjaxMethod]

        public string LoginNameUpdate(int gid,int hid,int type, string cd,string pwd)
        {
            string msg = "";
            if (type == 0)
            {
                if (!FGBRoleSystems.IsValidateCode(cd))
                {
                    return "链接已过期或不存在！请重新获取链接！";
                }
                else
                {
                    return "成功验证邮箱！";
                }
            }
            else
            {
                if (!FGBRoleSystems.ValidateUser(gid, FGBRoleSystems.GetCookie("username").ToString(), pwd, ValidateType.UserName))
                {
                    return "用户密码错误！";
                }
                if (type == 1)
                {
                    FGBGroup fgb = new FGBGroup();
                    fgb.languagetype = 0;
                    fgb.gid = gid;
                    fgb.hid = hid;
                    fgb = FGBRoleSystems.GetFGBEngine(fgb);
                    if (!FGBRoleSystems.UpdateEmail(fgb.emailfrom, fgb.emailalias, cd, out msg))
                    {
                        return "更新失败，邮箱已被使用！";
                    }
                    else
                    {
                        return "成功更新邮箱！";
                    }
                }
                else if (type == 2)
                {
                    if (!FGBRoleSystems.UpdateMobile(cd, out msg))
                    {
                        return "更新失败，手机已被使用！";
                    }
                    else
                    {
                        return "成功更新手机号！";
                    }
                }
                else
                {
                    return "错误指令！ ";
                }
            }

        }
        [AjaxPro.AjaxMethod]
        public string sendValidateEmail(int gid,int hid)
        {
            string email="";
            FGBGroup fgb = new FGBGroup();
            fgb.languagetype = 0;
            fgb.gid = gid;
            fgb.hid = hid;
            fgb = FGBRoleSystems.GetFGBEngine(fgb);
            if (FGBRoleSystems.sendValidateEmail(fgb.emailfrom,fgb.emailalias,out email))
            {
                return "发送成功,验证码已发送到您的" + email + "邮箱,请查收！";
            }
            else
            {
                return "发送失败，邮箱不存在或错误邮箱！";
            }
        }

      

        #region SearchHotel

        //[AjaxPro.AjaxMethod]
        //public DataSet getCity(string cityid)
        //{
        //    return "";
            
        //    //Hashtable htCityDis = (Hashtable)HCRS.Web.FGB.Global.HtCityDis[cityid];
        //    //Hashtable htCityCom = (Hashtable)HCRS.Web.FGB.Global.HtCityCom[cityid];
        //    //string htCityNum = HCRS.Web.FGB.Global.HtCity[cityid].ToString();
        //    //return search.getCity(cityid, htCityDis, htCityCom, htCityNum);
        //}

        //[AjaxPro.AjaxMethod]
        //public DataTable getGroup(string cityid)
        //{
        //    Hashtable hashHotel = (Hashtable)HCRS.Web.FGB.Global.HtHotel;
        //    return search.getGroup(cityid, hashHotel);
        //}
        
        [AjaxPro.AjaxMethod]
        public void setCookie(string city,string cname)
        {
            //写入用户名 cookies
            HttpCookie cookie = new HttpCookie("Hubs1Fit");//
            cookie.Values.Add("city", city);
            cookie.Values.Add("cname",HttpContext.Current.Server.UrlEncode(cname));
            cookie.Expires = DateTime.Now.AddDays(365);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
        /*
        [AjaxPro.AjaxMethod]
        public string HotellistQuyuCity(string hotelName, int city, string district, string commercial, string checkIN, string checkOUT, string price_range, string airport_distance, string star_rate, string airPort_Code, string room, string adult, string child, int pageNumber, string Geography, string group, int gid)
        {
            return search.HotellistQuyuCity(hotelName, city, district, commercial, checkIN, checkOUT, price_range, airport_distance, star_rate, airPort_Code, room, adult, child, pageNumber, Geography, group, gid);
        }*/

        

        /*
        /// <summary>
        /// 获取城市价格列表
        /// </summary>
        /// <param name="cityid"></param>
        /// <param name="checkIN"></param>
        /// <param name="checkOUT"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string GetPrices(string array, string cityid, string rate, string checkIN, string checkOUT)
        {
            rate = rate.Replace(",","','");
           
            return search.GetPrices(array, cityid,"'"+ rate+"'", checkIN, checkOUT);
        }
        /// <summary>
        /// 获取城市酒店列表
        /// </summary>
        /// <param name="cityid"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string GetHotels(string Hotels, string cityid)
        {
            return search.GetHotels(Hotels, cityid);
        }
        /// <summary>
        /// 获取城市地图坐标
        /// </summary>
        /// <param name="local">地图坐标对象</param>
        /// <param name="cityid">城市ｉｄ</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public string GetCityLocal(string local, string cityid)
        {
            return search.CityLocal(local, cityid);
        }
        */
        /// <summary>
        /// 设置关键字
        /// </summary>
        /// <param name="cityid"></param>
        /// <param name="hotelname"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SetCityKeywords(int cityid, string hotelname,string address)
        {
            hotelname = hotelname.Trim();
            address = address.Trim();
            return search.SetCityKeywords(cityid, hotelname, address);
        }
        #endregion
    }
}
